package com.gzc.just.play.last.war.sceneserver.goods;

/**
 * 背包物品项 - 表示背包中的一个物品
 *
 * @author AI编程助手
 * @version 1.0
 * @since 2025-11-22
 */
public class InventoryItem {
    
    private final int goodsId;
    private int quantity;
    private int level;              // 物品等级（装备可升级）
    private boolean equipped;       // 是否已装备
    private long obtainTime;        // 获得时间
    
    /**
     * 创建背包物品项
     *
     * @param goodsId 物品ID
     * @param quantity 数量
     */
    public InventoryItem(int goodsId, int quantity) {
        this.goodsId = goodsId;
        this.quantity = Math.max(1, quantity);
        this.level = 1;
        this.equipped = false;
        this.obtainTime = System.currentTimeMillis();
    }
    
    /**
     * 创建背包物品项（带等级）
     */
    public InventoryItem(int goodsId, int quantity, int level) {
        this.goodsId = goodsId;
        this.quantity = Math.max(1, quantity);
        this.level = level;
        this.equipped = false;
        this.obtainTime = System.currentTimeMillis();
    }
    
    // Getters and Setters
    
    public int getGoodsId() {
        return goodsId;
    }
    
    public int getQuantity() {
        return quantity;
    }
    
    public void setQuantity(int quantity) {
        this.quantity = Math.max(0, quantity);
    }
    
    public void addQuantity(int amount) {
        this.quantity += amount;
    }
    
    public void reduceQuantity(int amount) {
        this.quantity = Math.max(0, this.quantity - amount);
    }
    
    public int getLevel() {
        return level;
    }
    
    public void setLevel(int level) {
        this.level = Math.max(1, level);
    }
    
    public boolean isEquipped() {
        return equipped;
    }
    
    public void setEquipped(boolean equipped) {
        this.equipped = equipped;
    }
    
    public long getObtainTime() {
        return obtainTime;
    }
    
    /**
     * 检查物品是否为空（数量为0）
     */
    public boolean isEmpty() {
        return quantity <= 0;
    }
    
    /**
     * 克隆物品
     */
    public InventoryItem clone() {
        InventoryItem item = new InventoryItem(goodsId, quantity, level);
        item.equipped = this.equipped;
        item.obtainTime = this.obtainTime;
        return item;
    }
    
    @Override
    public String toString() {
        return String.format("InventoryItem{goodsId=%d, quantity=%d, level=%d, equipped=%b}",
            goodsId, quantity, level, equipped);
    }
}
